package com.liuugoqing.structural.facade;

/**
 * 外观（Facade）角色：为多个子系统对外提供一个共同的接口
 * 内聚子系统
 *
 * @Author : liugq
 * @Date : 2022/7/4 22:51
 * @See : 参考类
 * @Since： JDK1.8
 * @Version : 1.0
 */
public class SmartAppliancesFacade {
    private Light light;
    private TV tv;
    private AirCondition airCondition;

    public SmartAppliancesFacade() {
        light = new Light();
        tv = new TV();
        airCondition = new AirCondition();
    }

    /**
     * 识别文字
     * @param message
     */
    public void say(String message) {
        if (message.contains("打开")) {
            on();
        } else if (message.contains("关闭")) {
            off();
        } else {
            System.out.println("我还听不懂你说的！！！");
        }
    }

    //一键开电器
    private void on() {
        light.on();
        tv.on();
        airCondition.on();
    }

    //一键关电器
    private void off() {
        light.off();
        tv.off();
        airCondition.off();
    }
}
